/**
 * Copyright (C) 2012  TopicBankEx
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.oc.mba.entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import com.j256.ormlite.dao.ForeignCollection;
import com.oc.mba.presist.Answer;
import com.oc.mba.presist.Solution;
import com.oc.mba.presist.Technique;
import com.oc.mba.presist.Topic;

/**
 * 
 * @author xiaoyu.wang
 * @date 2012-3-6
 */
public class TopicEntity implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 9045314891556940176L;

	/** 数据库ID **/
	private Long id;

	/** 问题ID **/
	private Long topicId;
	
	/** 试卷ID **/
	private Long paperId;

	/** 序号 **/
	private int index;

	/** 问题题干 **/
	private String title;

	/** 图片 **/
	private String image;

	/** 是否完成 **/
	private boolean finish;
	
	/** 是否正确 **/
	private boolean correct;

	/** 备选答案 **/
	private List<AnswerEntity> answers = new ArrayList<AnswerEntity>();

	/** 解题方案 **/
	private String solution;

	/** 解题技巧 **/
	private String technique;

	/**
	 * 构造方法
	 * @param topic
	 */
	public TopicEntity (Topic topic) {
		this.id = topic.getId();
		this.topicId = topic.getTopicId();
		// 数据库ID
		this.paperId = topic.getPaper().getId();
		this.index = topic.getIndex();
		this.title = topic.getTitle();
		this.image = topic.getImage();
		this.finish = false;
		
		ForeignCollection<Answer> topicAnswer = topic.getAnswers();
		for (Answer ans : topicAnswer) {
			answers.add(new AnswerEntity(ans));
		}
		
		ForeignCollection<Solution> topicSolution = topic.getSolution();
		for (Solution sol : topicSolution) {
			solution = sol.getContent();
		}
		
		ForeignCollection<Technique> topicTechnique = topic.getTechnique();
		for (Technique tech : topicTechnique) {
			technique = tech.getContent();
		}
	}
	
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Long getTopicId() {
		return topicId;
	}

	public void setTopicId(Long topicId) {
		this.topicId = topicId;
	}

	public int getIndex() {
		return index;
	}

	public void setIndex(int index) {
		this.index = index;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getImage() {
		return image;
	}

	public void setImage(String image) {
		this.image = image;
	}

	public boolean isFinish() {
		return finish;
	}

	public void setFinish(boolean finish) {
		this.finish = finish;
	}

	public boolean isCorrect() {
		return correct;
	}

	public void setCorrect(boolean correct) {
		this.correct = correct;
	}

	public List<AnswerEntity> getAnswers() {
		return answers;
	}

	public void setAnswers(List<AnswerEntity> answers) {
		this.answers = answers;
	}

	public String getSolution() {
		return solution;
	}

	public void setSolution(String solution) {
		this.solution = solution;
	}

	public String getTechnique() {
		return technique;
	}

	public void setTechnique(String technique) {
		this.technique = technique;
	}

	public Long getPaperId() {
		return paperId;
	}

	public void setPaperId(Long paperId) {
		this.paperId = paperId;
	}

	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		sb.append("id=").append(id);
		sb.append(",topicId=").append(topicId);
		sb.append(",finish=").append(finish);
		return sb.toString();
	}

	
}
